Matplotlib Tutorial Part 13 - Live Graph


In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
filename = 'Matplotlib Tutorial Part 13 - Data'

Animation


In [9]:
fig = plt.figure(figsize=(17,9))

ax1 = plt.subplot2grid((1,1),(0,0))

# Get Data
def animate(i):
    raw_data = open(filename,'r').read()
    lines = raw_data.split('\n')
    selected_lines = (line.split(',') for line in lines if len(line) > 1)
    xs, ys = zip(*selected_lines)
    ax1.clear()
    ax1.plot(xs,ys)

# Animate
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()